<layout name="layout"/>
<include file="./nav"/>

<link rel="stylesheet" type="text/css" href="__PUBLIC__/media/css/select2_metro.css" />
<!-- BEGIN CONTAINER -->

<style type="text/css">
    ul li {list-style: none;}
    #ul_pic_list li{margin:5px; }
    #old_pic_list li{float:left;width:150px;margin:5px;}
    #cat_list{margin:0;width:250px;}
    #cat_list li{margin:5px;}

</style>

<div class="page-container row-fluid">

    <!-- BEGIN PAGE -->

    <div class="page-content">

        <!-- BEGIN PAGE CONTAINER-->

        <div class="container-fluid">

            <!-- BEGIN PAGE HEADER-->

            <div class="row-fluid">

                <div class="span12">

                    <h3 class="page-title">{$_page_title}</h3>

                    <ul class="breadcrumb">

                        <li>

                            <i class="icon-home"></i>

                            <a href="{:U('Index/index')}">首页</a>

                            <span class="icon-angle-right"></span>

                        </li>

                        <li>

                            <a href="#">{$_module_name}</a>

                            <span class="icon-angle-right"></span>

                        </li>

                        <li><a href="#">{$_page_btn_name}</a></li>

                    </ul>

                </div>

            </div>

            <!-- END PAGE HEADER-->

            <!-- BEGIN PAGE CONTENT-->

            <div class="row-fluid">

                <div class="span12">

                    <div class="tabbable tabbable-custom boxless">

                        <ul class="nav nav-tabs">

                            <li class="active">
                                <a href="#tab_1" data-toggle="tab"><span class="tab-front" >通用信息</span></a>
                            </li>

                            <li>
                                <a class="" href="#tab_2" data-toggle="tab"><span class="tab-back" >商品描述</span></a>
                            </li>

                            <li>
                                <a href="#tab_3" data-toggle="tab"><span class="tab-back" >会员价格</span></a>
                            </li>

                            <li>
                                <a class="" href="#tab_4" data-toggle="tab"><span class="tab-back" >商品属性</span></a>
                            </li>

                            <li>
                                <a class="" href="#tab_5" data-toggle="tab"><span class="tab-back" >商品相册</span></a>
                            </li>

                        </ul>
                        <form enctype="multipart/form-data" action="__SELF__" method="post" >
                            <input type="hidden" name="id" value="<?php echo $data['id']?>">
                            <div class="tab-content">

                                <!--基本信息start-->
                                <div class="tab-pane active" id="tab_1">

                                    <div class="portlet box blue">

                                        <div class="portlet-title">

                                            <div class="caption"><i class="icon-reorder"></i>通用信息</div>

                                            <div class="tools">

                                                <a href="javascript:;" class="collapse"></a>

                                                <a href="#portlet-config" data-toggle="modal" class="config"></a>

                                                <a href="javascript:;" class="reload"></a>

                                                <a href="javascript:;" class="remove"></a>

                                            </div>

                                        </div>

                                        <div class="portlet-body form">

                                            <!-- BEGIN FORM-->

                                            <div class="row-fluid">
                                                <div class="span5">

                                                    <div class="control-group">

                                                        <label class="control-label" >商品名称</label>

                                                        <div class="controls">

                                                            <input type="text" name="goods_name" value="{$data.goods_name}">

                                                        </div>

                                                    </div>

                                                    <div class="control-group">

                                                        <label class="control-label" >主分类</label>

                                                        <div class="controls">

                                                            <select name="cat_id">
                                                                <option value="">选择分类</option>
                                                                <?php foreach ($catData as $k=>$v):
                                                                if($v['id'] == $data['cat_id'])
                                                                $select = 'selected="selected"';
                                                                else
                                                                $select = '';
                                                                ?>
                                                                <option <?php echo $select; ?> value="<?php echo $v['id']; ?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                                                                <?php endforeach; ?>
                                                            </select>

                                                        </div>

                                                    </div>

                                                <div class="control-group">

                                                    <label class="control-label" >扩展分类 <input type="button" onclick="$('#cat_list').append($('#cat_list').find('li').eq(0).clone());" id="btn_add_cat" value="添加一个"></label>

                                                    <div class="controls">

                                                        <ul id="cat_list">
                                                            <?php if($gcData):  ?>
                                                            <?php foreach($gcData as $k1=>$v1): ?>
                                                            <li>
                                                                <select name="ext_cat_id[]">
                                                                    <option value="">选择分类</option>
                                                                    <?php foreach($catData as $k=>$v):
                                                                    if($v['id'] == $v1['cat_id']){
                                                                    $select = 'selected="selected"';
                                                                    } else {
                                                                    $select = '';
                                                                    }
                                                                    ?>
                                                                    <option <?php echo $select; ?> value="<?php echo $v['id']?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                                                                    <?php endforeach; ?>
                                                                </select>
                                                            </li>
                                                            <?php endforeach; ?>
                                                            <?php else: ?>
                                                            <li>
                                                                <select name="ext_cat_id[]">
                                                                    <option value="">选择分类</option>
                                                                    <?php foreach($catData as $k=>$v): ?>
                                                                    <option value="<?php echo $v['id']; ?>"><?php echo str_repeat('-',8*$v['level']).$v['cat_name']; ?></option>
                                                                    <?php endforeach; ?>
                                                                </select>
                                                            </li>
                                                            <?php endif; ?>
                                                        </ul>

                                                    </div>

                                                </div>

                                                <div class="control-group">

                                                    <label class="control-label" >品牌名称</label>

                                                    <div class="controls">

                                                        <?php buildSelect('brand','brand_id','id','brand_name',$data['brand_id']); ?>

                                                    </div>

                                                </div>

                                                <div class="control-group">

                                                    <label class="control-label" >商品数量</label>

                                                    <div class="controls">

                                                        <input type="text" name="goods_number" size="8" value=""/>

                                                    </div>

                                                </div>

                                                <div class="control-group">

                                                    <label class="control-label" >商品LOGO</label>

                                                    <div class="controls">

                                                        <?php echo showImage($data['sm_logo']); ?>
                                                        <input type="file" name="logo" size="95" />

                                                    </div>

                                                </div>

                                                <div class="control-group">

                                                    <label class="control-label" >排序</label>

                                                    <div class="controls">

                                                        <input type="text" name="sort_num" size="8" value="<?php echo $data['sort_num']; ?>"/>

                                                    </div>

                                                </div>
                                                </div>

                                                <div class="span6 ">

                                                    <div class="control-group">

                                                        <label class="control-label" >是否上架</label>

                                                        <div class="controls">

                                                            <input type="radio" name="is_onsale" value="1" <if condition="$data.is_onsale eq 1"> checked="true" </if> /> 是
                                                            <input type="radio" name="is_onsale" value="0" <if condition="$data.is_onsale eq 0"> checked="true" </if> /> 否

                                                        </div>

                                                    </div>
                                                    <br/>

                                                    <div class="control-group">

                                                        <label class="control-label" >是否新品</label>

                                                        <div class="controls">

                                                            <input type="radio" name="is_new" value="是" <if condition="$data.is_new eq '是'"> checked="true" </if> /> 是
                                                            <input type="radio" name="is_new" value="否" <if condition="$data.is_new eq '否'"> checked="true" </if>/> 否
                                                        </div>

                                                    </div>
                                                    <br/>

                                                    <div class="control-group">

                                                        <label class="control-label" >是否精品</label>

                                                        <div class="controls">

                                                            <input type="radio" name="is_best" value="是" <if condition="$data.is_best eq '是'"> checked="true" </if>/> 是
                                                            <input type="radio" name="is_best" value="否" <if condition="$data.is_best eq '否'"> checked="true" </if>/> 否

                                                        </div>

                                                    </div>
                                                    <br/>

                                                    <div class="control-group">

                                                        <label class="control-label" >是否热卖</label>

                                                        <div class="controls">

                                                            <input type="radio" name="is_hot" value="是" <if condition="$data.is_hot eq '是'"> checked="true" </if>/> 是
                                                            <input type="radio" name="is_hot" value="否" <if condition="$data.is_hot eq '否'"> checked="true" </if>/> 否

                                                        </div>

                                                    </div>
                                                    <br/>

                                                    <div class="control-group">

                                                        <label class="control-label" >是否推荐到楼层</label>

                                                        <div class="controls">

                                                            <input type="radio" name="is_floor" value="1" <if condition="$data.is_floor eq '是'"> checked="true" </if> /> 是
                                                            <input type="radio" name="is_floor" value="0" <if condition="$data.is_floor eq '否'"> checked="true" </if> /> 否

                                                        </div>

                                                    </div>

                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span12 ">

                                                        <div class="control-group">

                                                            <label class="control-label">促销价格</label>

                                                            <div class="controls">

                                                                价格：￥<input type="text" name="promote_price" size="8" value="0.00"/> 元
                                                                <p>开始时间：<input type="text" id="promote_start_date" name="promote_start_date"/>
                                                                    结束时间：<input type="text" id="promote_end_date" name="promote_end_date"/></p>

                                                            </div>

                                                        </div>

                                                    </div>
                                                </div>
                                                <div class="form-actions" >

                                                    <button type="submit" class="btn blue"><i class="icon-ok"></i>修改</button>
                                                    <button type="button" class="btn" onclick="window.history.back();">取消</button>

                                                </div>
                                            </div>


                                            <!-- END FORM-->
                                        </div>

                                    </div>

                                </div>
                                <!--基本信息end-->

                                <!--商品描述start-->
                                <div class="tab-pane " id="tab_2">

                                    <div class="portlet box green">
                                        <div class="portlet-title">
                                            <div class="caption"><i class="icon-reorder"></i>商品描述</div>
                                        </div>
                                        <textarea name="goods_desc" cols="40" rows="3" id="goods_desc">{$data.goods_desc}</textarea>

                                    </div>
                                    <div class="form-actions">

                                        <button type="submit" class="btn blue"><i class="icon-ok"></i>修改</button>

                                        <button type="button" class="btn" onclick="window.history.back();">取消</button>

                                    </div>
                                </div>
                                <!--商品描述end-->

                                <!--商品价格start-->
                                <div class="tab-pane " id="tab_3">

                                    <div class="portlet box blue">

                                        <div class="portlet-title">

                                            <div class="caption"><i class="icon-reorder"></i>会员价格</div>

                                        </div>

                                        <div class="portlet-body form">

                                            <!-- BEGIN FORM-->

                                            <div class="form-horizontal form-view">
                                                <div class="row-fluid">


                                                    <!--/span-->

                                                    <div class="span6 ">

                                                        <div class="control-group">

                                                            <label class="control-label">市场价格：</label>

                                                            <div class="controls">

                                                                <input type="text" name="market_price" value="{$data.market_price}" size="20" />

                                                            </div>

                                                        </div>

                                                    </div>

                                                    <!--/span-->

                                                </div>

                                                <!--/row-->

                                                <div class="row-fluid">

                                                    <div class="control-group">

                                                        <label class="control-label">本店价格：</label>

                                                        <div class="controls">

                                                            <input type="text" name="shop_price" value="{$data.shop_price}" size="20"/>

                                                        </div>

                                                    </div>

                                                    <!--/span-->
                                                    <br/><br/>
                                                    <div class="span6 " style="margin-left:0">

                                                        <div class="control-group">

                                                            <label class="control-label">会员价格：</label>

                                                            <div class="controls">

                                                                <foreach name="mlData" item="val">
                                                                    <strong>{$val.level_name}</strong>
                                                                    ：￥<input type="text" name="member_price[{$val.id}]" size="8" value="<?php echo $mpData[$val['id']];?>"/>元<br/><br/>
                                                                </foreach>

                                                            </div>

                                                        </div>

                                                    </div>

                                                    <!--/span-->

                                                </div>
                                                <div class="form-actions">

                                                    <button type="submit" class="btn blue"><i class="icon-ok"></i>修改</button>
                                                    <button type="button" class="btn" onclick="window.history.back();">取消</button>

                                                </div>
                                            </div>

                                            <!-- END FORM-->

                                        </div>

                                    </div>

                                </div>
                                <!--商品价格end-->

                                <!--商品属性start-->
                                <div class="tab-pane"  id="tab_4">

                                    <div class="portlet box blue">

                                        <div class="portlet-title">

                                            <div class="caption"><i class="icon-reorder"></i>商品属性</div>

                                        </div>

                                        <div class="portlet-body form">

                                            <!-- BEGIN FORM-->
                                            <table  width="90%"  align="center" >

                                                <tr>
                                                    <td>商品类型：<?php buildSelect('Type','type_id','id','type_name',$data['type_id']); ?></td>
                                                </tr>
                                                <tr>
                                                    <td >
                                                        <ul id="attr_list">
                                                            <?php
                                                            $attrId = array();
                                                            foreach($gaData as $k => $v):
                                                            if(in_array($v['attr_id'],$attrId))
                                                            $opt = '[-]';
                                                            else
                                                            $opt = '[+]';
                                                            $attrId[] = $v['attr_id'];
                                                            ?>
                                                            <li>
                                                                <input type="hidden" name="goods_attr_id[]" value="<?php echo $v['id']; ?>"/>
                                                                <?php if($v['attr_type'] == '可选'): ?>
                                                                <a onclick="addNewAttr(this);" href="#"><?php echo $opt; ?></a>
                                                                <?php endif; ?>
                                                                <?php echo $v['attr_name']; ?> :
                                                                <?php if($v['attr_option_values']):
                                                                    $attr = explode(',',$v['attr_option_values']);
                                                                ?>
                                                                <select name="attr_value[<?php echo $v['attr_id']; ?>][]">
                                                                    <option value="">请选择</option>
                                                                    <?php foreach($attr as $k1 => $v1):
                                                                    if($v1 == $v['attr_value'])
                                                                    $select='selected="selected"';
                                                                    else
                                                                    $select='';
                                                                    ?>
                                                                    <option <?php echo $select; ?> value="<?php echo $v1; ?>"><?php echo $v1; ?></option>
                                                                    <?php endforeach; ?>
                                                                </select>
                                                                <?php else: ?>
                                                                <input type="text" name="attr_value[<?php echo $v['attr_id']; ?>][]" value="<?php echo $v['attr_value']; ?>"/>
                                                                <?php endif; ?>
                                                            </li>
                                                            <?php endforeach; ?>
                                                        </ul>
                                                    </td>
                                                </tr>
                                            </table>
                                            <!-- END FORM-->
                                            <div class="form-actions">

                                                <button type="submit" class="btn blue"><i class="icon-ok"></i>修改</button>

                                                <button type="button" class="btn" onclick="window.history.back();">取消</button>

                                            </div>
                                        </div>

                                    </div>

                                </div>
                                <!--商品属性end-->

                                <!--商品相册start-->
                                <div class="tab-pane"  id="tab_5">

                                    <div class="portlet box blue ">

                                        <div class="portlet-title">

                                            <div class="caption"><i class="icon-reorder"></i>商品相册</div>

                                        </div>

                                    </div>
                                    <table width="90%"  align="center" >
                                        <tr>
                                            <td>
                                                <input type="button" id="btn_add_pic" value="添加一张"/>
                                                <hr/>
                                                <ul id="ul_pic_list"></ul>
                                                <hr/>
                                                <ul id="old_pic_list">
                                                    <?php foreach($gpData as $k=>$v): ?>
                                                    <li>
                                                        <input type="button" pic_id="<?php echo $v['id']; ?>" class="btn_del_pic" value="删除"><br/>
                                                        <?php showImage($v['mid_pic'],150); ?>
                                                    </li>
                                                    <?php endforeach; ?>
                                                </ul>
                                            </td>
                                        </tr>
                                    </table>
                                    <div class="form-actions">

                                        <button type="submit" class="btn blue"><i class="icon-ok"></i>保存</button>
                                        <button type="button" class="btn">取消</button>

                                    </div>
                                </div>
                                <!--商品相册end-->

                            </div>
                        </form>
                    </div>

                </div>

            </div>

            <!-- END PAGE CONTENT-->

        </div>

        <!-- END PAGE CONTAINER-->

    </div>

    <!-- END PAGE -->

</div>

<!-- END CONTAINER -->

<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->

<!-- BEGIN CORE PLUGINS -->

<script src="__PUBLIC__/media/js/jquery-1.10.1.min.js" type="text/javascript"></script>

<script src="__PUBLIC__/media/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>

<!-- IMPORTANT! Load jquery-ui-1.10.1.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->

<script src="__PUBLIC__/media/js/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>

<script src="__PUBLIC__/media/js/bootstrap.min.js" type="text/javascript"></script>

<!--[if lt IE 9]>

<script src="__PUBLIC__/media/js/excanvas.min.js"></script>

<script src="__PUBLIC__/media/js/respond.min.js"></script>

<![endif]-->

<script src="__PUBLIC__/media/js/jquery.slimscroll.min.js" type="text/javascript"></script>

<script src="__PUBLIC__/media/js/jquery.blockui.min.js" type="text/javascript"></script>

<script src="__PUBLIC__/media/js/jquery.cookie.min.js" type="text/javascript"></script>

<script src="__PUBLIC__/media/js/jquery.uniform.min.js" type="text/javascript" ></script>

<!-- END CORE PLUGINS -->

<!-- BEGIN PAGE LEVEL PLUGINS -->

<script type="text/javascript" src="__PUBLIC__/media/js/select2.min.js"></script>

<!-- END PAGE LEVEL PLUGINS -->

<!-- BEGIN PAGE LEVEL SCRIPTS -->

<script src="__PUBLIC__/media/js/app.js"></script>

<script src="__PUBLIC__/media/js/form-samples.js"></script>

<!-- END PAGE LEVEL SCRIPTS -->

<script>

    jQuery(document).ready(function() {

        // initiate layout and plugins

        App.init();

        FormSamples.init();

    });

</script>

<!-- END JAVASCRIPTS -->
<link href="__PUBLIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="__PUBLIC__/umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__//umeditor/third-party/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/umeditor/lang/zh-cn/zh-cn.js"></script>
<!--时间插件-->
<link href="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/datepicker-zh_cn.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.css" />
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/i18n/jquery-ui-timepicker-addon-i18n.min.js"></script>
<script>
    // 添加时间插件
    $.timepicker.setDefaults($.timepicker.regional['zh-CN']);  // 设置使用中文

    $("#promote_start_date").datetimepicker();
    $("#promote_end_date").datetimepicker();
</script>

<script type="text/javascript">
    UM.getEditor('goods_desc',{
        initialFrameWidth:'100%',
        initialFrameHeight:350
    });

    $("#tabbar-div p span").click(function () {
        var i = $(this).index();
        $(".tab_table").hide();
        $(".tab_table").eq(i).show();
        $(".tab-front").removeClass("tab-front").addClass("tab-back");
        $(this).removeClass("tab-back").addClass("tab-front");
    });

    $("#btn_add_pic").click(function () {
        var file = '<li><input type="file" name="pic[]"/></li>';
        $("#ul_pic_list").append(file);
    });

    $(".btn_del_pic").click(function () {
        if(confirm('是否删除?')){
            var li = $(this).parent();
            var pid = $(this).attr("pic_id");
            $.ajax({
                type : "GET",
                url  : "<?php echo U('ajaxDelPic','',FALSE); ?>/picid/"+pid,
                success : function (data) {
                    li.remove();
                }
            });
        }
    });



    $("select[name=type_id]").change(function () {
        var typeId = $(this).val();
        if(typeId > 0){
            $.ajax({
                type : "GET",
                url  : "<?php echo U('ajaxGetAttr','',FALSE); ?>/type_id/"+typeId,
                dataType : "json",
                success : function (data) {
                    var li = "";
                    $(data).each(function (k,v) {
                        li += '<li>';
                        //如果属性为可选值，则前面有个+
                        if(v.attr_type == '可选')
                            li += '<a onclick="addNewAttr(this);" href="#">[+]</a>';
                        //属性名称
                        li += v.attr_name + ' : ';
                        //如果属性是可选值则做下拉框，否则文本框
                        if(v.attr_option_values == ""){
                            li += '<input type="text" name="attr_value['+v.id+'][]" />';
                        } else {
                            li += '<select name="attr_value['+v.id+'][]"><option value="">请选择</option>';
                            var _attr = v.attr_option_values.split(',');
                            for(var i=0;i<_attr.length;i++){
                                li += '<option value="'+_attr[i]+'">';
                                li += _attr[i];
                                li += '</option>';
                            }
                            li += '</select>';
                        }
                        li += '</li>';
                    });
                    $("#attr_list").html(li);
                }
            });
        }
        else
            $("#attr_list").html("");
    });

    function addNewAttr(a) {
        var li = $(a).parent();
        if($(a).text() == '[+]'){
            var newLi = li.clone();
            newLi.find("option:selected").removeAttr("selected");
            newLi.find("input[name='goods_attr_id[]']").val("");
            newLi.find("a").text('[-]');
            li.after(newLi);
        } else {
            var gaid = li.find("input[name='goods_attr_id[]']").val();
            if(gaid == ''){
                li.remove();
            } else {
                if(confirm('如果删除这个属性，那么相关的库存量数据也会一起删除，确定要删除吗？')){
                    $.ajax({
                        type : "GET",
                        url : "<?php echo U('ajaxDelAttr?goods_id='.$data['id'],'',FALSE); ?>/gaid/"+gaid,
                        success : function (data) {
                            li.remove();
                        }
                    });
                }
            }
        }
    }
</script>
